<template>
  <basePage :show-tabbar="true" :page-params="pageParams">
    <template v-if="indexShow">
      <view class="content">
        <!--        <view @click="aa">订单确认页</view>-->
        <image style="position: absolute; height: 100%; width: 100%" :src="vuex_imgPath + '/home_page.jpg'" />
      </view>
      <!-- 关注微信公众号 -->
      <!--     #ifdef MP-WEIXIN-->
      <official-account :style="'position: fixed; width: 100%; bottom: '+(safeBottom+50)+'px;'" />
      <!--    #endif-->
    </template>
  </basePage>
</template>
<script>
import basePage from '@/components/base-page'
import { pushMeber } from '@/api/login.js'
export default {
  components: {
    basePage,
  },
  data() {
    return {
      title: 'Index',
      pageParams: {
        // state: 'ERROR',
        emptyTitle: '信号可能跑到外星球了哦～',
        errorTitle: '请求失败',
        showButton: true
      },
      indexShow: false,
      safeBottom: 0
    }
  },
  mounted() {
    this.setSafeBottomFn()
    if (!this.vuex_loginStatus || (this.vuex_loginStatus && this.vuex_memberInfo && (this.vuex_memberInfo.accountType == 20 || this.vuex_memberInfo.accountType == 30))) {
      this.callbackUrl = '/shopIndex/shopIndex'
      uni.redirectTo({ url: this.callbackUrl })
    } else {
      this.indexShow = true
    }
  },
  onLoad(option) {
    // #ifdef MP-ALIPAY
    if (uni.getStorageSync('inviteCode')) {
      this.bindMember(uni.getStorageSync('inviteCode'))
    }
    // #endif
    // #ifdef MP-WEIXIN
    if (option.q) {
      const src = decodeURIComponent(option.q)
      if (src.includes('inviteCode')) {
        const inviteCode = src.match(/inviteCode=(\S*)/)[1]
        uni.setStorageSync('inviteCode', inviteCode)
        this.bindMember(inviteCode)
      }
    }
    // #endif

    // if (!!uni.getStorageSync('inviteCode')) {
    //   this.bindMember(uni.getStorageSync('inviteCode'))
    // }
  },
  methods: {
    /*aa() {
      uni.navigateTo({ url: '/ycPayments/confirmOrders/index' })
    },*/
    /*安全距离设置*/
    setSafeBottomFn() {
      // #ifdef MP-WEIXIN
      if (this.vuex_systemInfo && this.vuex_systemInfo.length > 0 && this.vuex_systemInfo[1].safeAreaInsets) {
        this.safeBottom = this.vuex_systemInfo[1].safeAreaInsets.bottom / 2
      }
      // #endif
      // #ifdef MP-ALIPAY
      if (this.vuex_systemInfo && this.vuex_systemInfo.length > 0 && this.vuex_systemInfo[1].safeAreaInsets) {
        const bottom = this.vuex_systemInfo[1].safeAreaInsets.bottom > 50 ? this.vuex_systemInfo[1].safeArea.bottom : this.vuex_systemInfo[1].safeAreaInsets.bottom
        this.safeBottom = bottom / 2
      }
      // #endif
      console.log(this.safeBottom);
    },
    bindMember(inviteCode) {
      const params = {
        loginAccount: this.vuex_accountInfo.loginAccount,
        inviteCode: inviteCode
      }
      pushMeber(params).then((res) => {
        console.log(res)
      })
    }
  }
}
</script>

<style>

</style>
